package com.ruoyi.framework.config;

import com.ruoyi.framework.datasource.DynamicDataSource;
import org.openoa.base.util.SpringBeanUtils;
import org.openoa.engine.conf.engineconfig.DataSourceFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * 获取ruoyi框架的DynamicDataSource默认数据源,这里设计上有些瑕疵,必须要配置spring.antflow.xxx,否则不会生效
 */
@Primary
@Component
public class AntFlowDruidDatasourceConfig implements DataSourceFactory{

    @Override
    public DataSource createDataSource(String url, String username, String password) {
        DataSource dataSource = SpringBeanUtils.getBean(DataSource.class);
        DataSource resolvedDefaultDataSource = ((DynamicDataSource) dataSource).getResolvedDefaultDataSource();
        return resolvedDefaultDataSource;
    }

}
